#!/usr/bin/env node

const inquirer = require('inquirer');
const fs = require('fs');
const path = require('path');
const ejs = require('ejs')

inquirer.prompt([
  {
    type: 'input',
    name: 'name',
    message: 'Your project name?',
    default: 'this is name'
  },
  {
    type: 'input',
    name: 'title',
    message: 'Your project title?',
    default: 'this is title'
  }
]).then(anwsers => {
  const tmplDir = path.join(__dirname, 'templates');
  const destDir = process.cwd();
  fs.readdir(tmplDir, (err, files) => {
    if (err) throw err;
    files.forEach(file => {
      ejs.renderFile(path.join(tmplDir, file), anwsers, (err, result) => {
        if (err) throw err;
        fs.writeFileSync(path.join(destDir, file), result)
      })
    });
  })
})